package com.jzr.bedside.ui.skill

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.jzr.bedside.R
import com.jzr.bedside.base.BaseActivity
import com.jzr.bedside.bean.InspectReportListBean
import com.jzr.bedside.presenter.contract.InspectActivityContract
import com.jzr.bedside.presenter.impl.InspectActivityImpl
import com.jzr.bedside.ui.adapter.InspectAdapter
import com.jzr.bedside.utils.PreferUtil
import kotlinx.android.synthetic.main.actionbar_root_layout.*
import kotlinx.android.synthetic.main.activity_inspect.*

class InspectActivity : BaseActivity(), View.OnClickListener, InspectActivityContract.View {

    private val mPresenter = InspectActivityImpl()
    private var data: MutableList<InspectReportListBean.DataBean> = ArrayList()
    private var adapter: InspectAdapter? = null

    override fun getLayoutId(): Int {
        return R.layout.activity_inspect
    }

    override fun attachView() {
        mPresenter.attachView(this)
    }

    override fun detachView() {
        mPresenter.detachView()
    }

    override fun initView() {
        ivRight.setOnClickListener(this)

        PreferUtil.getInstance().cureNo?.let { it ->
            mPresenter.getInspectReportList(
                this@InspectActivity, "admissionId",
                it
            )
        }

        adapter = InspectAdapter(data)
        rvInspect.adapter = adapter
        val manager = LinearLayoutManager(this)
        rvInspect.layoutManager = manager


    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.ivRight -> {
                finish()
            }
        }
    }

    override fun getInspectReportListSuccess(data: InspectReportListBean?) {
        adapter?.let {
            it.setNewData(data?.data)
            it.notifyDataSetChanged()
        }
    }

    override fun showError(message: String?) {

    }
}
